﻿using HCQ2_Model;
using HCQ2_Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using HCQ2_Common;
using HCQ2_Model.VR.Params;
using HCQ2_Model.DocModel.APIResultModel;

namespace HCQ2UI_Logic
{
    /// <summary>
    ///  教学监控（体验用户）
    /// </summary>
    public class ExperUserController: BaseLogic
    {
        //*********************************1.0 体验记录*****************************************
        #region 1.0 体验记录首次进入页面 +ActionResult ExperRecordList()
        /// <summary>
        ///  体验记录首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult ExperRecordList()
        {
            return View();
        }
        #endregion

        #region 1.1 获取体验记录一栏数据 +ActionResult GetExperUserData()
        /// <summary>
        ///  获取体验记录一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetExperUserData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名，登录名
                fileName= RequestHelper.GetDeStrByName("fileName"),
                folderName = RequestHelper.GetDeStrByName("folderName"),
                inDate = RequestHelper.GetDeStrByName("inDate"),//进入时间
                outDate = RequestHelper.GetDeStrByName("outDate");//退出时间
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               orderType = RequestHelper.GetIntByName("orderType"),//排序
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, orderType = orderType, fileName = fileName, folderName = folderName, inDate = inDate, outDate = outDate, page = page, rows = rows };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            List<ExperienceRecord> list = operateContext.bllSession.T_VRExperienceRecord.GetRecordList(param);
            TableModel tModel = new TableModel()
            {
                total = operateContext.bllSession.T_VRExperienceRecord.GetRecordNumCount(param),
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 1.2 删除记录 +ActionResult DelExperById(int id)
        /// <summary>
        ///  删除记录
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelExperById(int id)
        {
            if (id <= 0)
                return operateContext.RedirectAjax(1, "需要删除的数据不存在~", "", "");
            int delCount = operateContext.bllSession.T_VRExperienceRecord.Delete(s => s.er_id == id);
            if (delCount > 0)
                return operateContext.RedirectAjax(0, "数据删除成功~", "", "");
            return operateContext.RedirectAjax(1, "数据删除失败~", "", "");
        }
        #endregion

        //*********************************2.0 当前位置*****************************************
        #region 2.0 当前位置首次进入页面 +ActionResult ExperRecordList()
        /// <summary>
        ///  当前位置首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult CurrentPointList()
        {
            return View();
        }
        #endregion

        #region 1.1 获取当前位置一栏数据 +ActionResult GetCurrentPointData()
        /// <summary>
        ///  获取当前位置一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCurrentPointData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名
                folderName = RequestHelper.GetDeStrByName("folderName"),//体验项目
                fileName = RequestHelper.GetDeStrByName("fileName");//体验作品
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, folderName = folderName, fileName = fileName, page = page, rows = rows };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            List<CurrentPointModel> list = operateContext.bllSession.T_VRCurrentPoint.GetCurrentPointList(param);
            TableModel tModel = new TableModel()
            {
                total = list.Count,
                rows = list?.Skip((param.page - 1) * param.rows)?.Take(param.rows)
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //*********************************3.0 在线用户*****************************************
        #region 3.0 在线用户首次进入页面 +ActionResult OnLineList()
        /// <summary>
        ///  在线用户首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult OnLineList()
        {
            return View();
        }
        #endregion

        #region 3.1 获取在线用户一栏数据 +ActionResult GetOnLineData()
        /// <summary>
        ///  获取在线用户一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetOnLineData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名
                folderName = RequestHelper.GetDeStrByName("folderName"),//体验项目
                fileName = RequestHelper.GetDeStrByName("fileName"),//体验作品
                lineStatus = RequestHelper.GetDeStrByName("lineStatus"); //在线状态
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, folderName = folderName, fileName = fileName, page = page, rows = rows, lineStatus = lineStatus };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            List<OnLineUserModel> list = operateContext.bllSession.T_VROnLineUser.GetOnLineList(param);
            TableModel tModel = new TableModel()
            {
                total = operateContext.bllSession.T_VROnLineUser.GetOnLineNum(param),
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //*********************************4.0 体验排行*****************************************
        #region 4.0 体验排行首次进入页面 +ActionResult RankList()
        /// <summary>
        ///  体验排行首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult RankList()
        {
            return View();
        }
        #endregion

        #region 4.1 获取体验排行一栏数据 +ActionResult GetRankData()
        /// <summary>
        ///  获取在线用户一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetRankData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名
                folderName = RequestHelper.GetDeStrByName("folderName"),//体验项目
                lineStatus= RequestHelper.GetDeStrByName("lineStatus"),//来源
                fileName = RequestHelper.GetDeStrByName("fileName"),//体验作品
                user_guid = operateContext.Usr.user_guid;
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, lineStatus = lineStatus, folderName = folderName, fileName = fileName, page = page, rows = rows };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            int total;
            List<ExperienceRankModel> list = operateContext.bllSession.T_VRExperienceRecord.GetRecordRankList(param, user_guid, out total);
            TableModel tModel = new TableModel()
            {
                total =total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //*********************************5.0 个人成绩*****************************************
        #region 5.0 个人成绩首次进入页面 +ActionResult VRScoreList()
        /// <summary>
        ///  个人成绩首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult VRScoreList()
        {
            return View();
        }
        #endregion

        #region 4.1 获取个人成绩一栏数据 +ActionResult GetRankData()
        /// <summary>
        ///  获取个人成绩一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetScoreData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名
                folderName = RequestHelper.GetDeStrByName("folderName"),//体验项目
                fileName = RequestHelper.GetDeStrByName("fileName");//体验作品
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, folderName = folderName, fileName = fileName, page = page, rows = rows };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            List<VRScoreModel> list = operateContext.bllSession.T_VRScore.GetOnLineList(param);
            TableModel tModel = new TableModel()
            {
                total = list.Count,
                rows = list?.Skip((param.page - 1) * param.rows)?.Take(param.rows)
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        //*********************************6.0 体验明细*****************************************
        #region 6.0 体验明细首次进入页面 +ActionResult ExperRecordDetail()
        /// <summary>
        ///  体验明细首次进入页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Element]
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult ExperRecordDetail()
        {
            return View();
        }
        #endregion

        #region 1.1 获取体验明细一栏数据 +ActionResult GetExperDetailData()
        /// <summary>
        ///  获取体验明细一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetExperDetailData()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),//用户名，登录名
                fileName = RequestHelper.GetDeStrByName("fileName"),
                folderName = RequestHelper.GetDeStrByName("folderName"),
                word = RequestHelper.GetDeStrByName("word"),//单词
                statusType = RequestHelper.GetDeStrByName("statusType"),//状态 
                inDate = RequestHelper.GetDeStrByName("inDate"),//进入时间
                outDate = RequestHelper.GetDeStrByName("outDate");//退出时间
            int page = Helper.ToInt(Request["page"]),
               rows = Helper.ToInt(Request["rows"]),
               orderType = RequestHelper.GetIntByName("orderType"),//排序
               userId = operateContext.Usr.user_id;
            ExperRecordModel param = new ExperRecordModel { userName = userName, fileName = fileName, folderName = folderName, word = word, orderType = orderType, statusType = statusType, inDate = inDate, outDate = outDate, page = page, rows = rows };
            if (!operateContext.bllSession.T_DocumentInfo.IsApproveLimit(userId))
                param.userId = userId;
            int total;
            List<ExperRecordDetailModel> list = operateContext.bllSession.T_VRExperienceDetail.GetExperDetailList(param,out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 1.2 删除记录 +ActionResult DelExperDetailById(int id)
        /// <summary>
        ///  删除记录
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelExperDetailById(int id)
        {
            if (id <= 0)
                return operateContext.RedirectAjax(1, "需要删除的数据不存在~", "", "");
            int delCount = operateContext.bllSession.T_VRExperienceDetail.Delete(s => s.ed_id == id);
            if (delCount > 0)
                return operateContext.RedirectAjax(0, "数据删除成功~", "", "");
            return operateContext.RedirectAjax(1, "数据删除失败~", "", "");
        }
        #endregion
    }
}
